package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2024-06-09
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Override
    public Map<String, Object> getTeacherFrontList(Page<EduTeacher> eduTeacherPage) {
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        baseMapper.selectPage(eduTeacherPage,eduTeacherQueryWrapper);
        List<EduTeacher> records = eduTeacherPage.getRecords();//集合
        long current = eduTeacherPage.getCurrent();//获取当前页页码
        long pages = eduTeacherPage.getPages();//返回的总页数
        long size = eduTeacherPage.getSize();//每页显示的记录数
        long total = eduTeacherPage.getTotal();//返回的总记录数据
        boolean hasNext = eduTeacherPage.hasNext();//是否有下页
        boolean hasPrevious = eduTeacherPage.hasPrevious();//是否有上页
        Map<String, Object> TeacherMap = new HashMap<>();
        TeacherMap.put("items",records);
        TeacherMap.put("current",current);
        TeacherMap.put("pages",pages);
        TeacherMap.put("size",size);
        TeacherMap.put("total",total);
        TeacherMap.put("hasNext",hasNext);
        TeacherMap.put("hasPrevious",hasPrevious);


        return TeacherMap;
    }
}
